package demo.cxf.soap_spring_cxf_wss4j;

import java.util.Iterator;

import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.io.CacheAndWriteOutputStream;
import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageContentsList;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;

public class MessageInterceptor extends AbstractPhaseInterceptor<Message> {
    
    //至少要一个带参的构造函数
    public MessageInterceptor(String phase) {
        super(phase);
    }
 
    public void handleMessage(Message message) throws Fault {
        System.out.println("############handleMessage##########");
        if (message.getDestination() != null) {
            System.out.println(message.getId() + "--:" + message.getDestination().getMessageObserver());
        }
        System.out.println(message);
        message.setContent(MessageContentsList.class,  "余乙迪被修改了");
        System.out.println(message);
        if (message.getExchange() != null) {
            System.out.println(message.getExchange().getInMessage() + "==:" + message.getExchange().getInFaultMessage());
            System.out.println(message.getExchange().getOutMessage() + "##:" + message.getExchange().getOutFaultMessage());
        }
    }
}
